/* ***********************
 * Version: MPL 1.1
 *
 * The contents of this file are subject to the Mozilla Public License Version
 * 1.1 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * The Original Code is SiteSponsors.js module.
 *
 * The Initial Developer of the Original Code is Rob Gerns.
 *
 * Portions created by the Initial Developer are Copyright (C) 2010
 * the Initial Developer. All Rights Reserved.
 *
 **************************/

/*************************************************
* Function Name(s): SiteSponsor; writeSponsors
*
* Purpose:
* Check to see if there are any sponsors defined in the 
* 'brief' section of the Oister file.  If so, for each
* sponsor create the necessary div and write the sponsor 
* information (and HTML for the link since the data should 
* be a URI) inside the div.
**************************************************/

function siteSponsors(xmlDocument){	

 if(xmlDocument.getElementsByTagName("sponsor")!=undefined && xmlDocument.getElementsByTagName("sponsor") !=null){
   
  //All of the sponsors elements defined in the Oister file put into an array 
  var checkSiteSponsors = xmlDocument.getElementsByTagName("sponsor"); 
 
 }
 
 //If there's at least one sponsor defined, read in the info
 if(checkSiteSponsors.length > 0 ){
	
  //Loop around to read all of the sponsors elements
  for(var i = 0; i < checkSiteSponsors.length; i++){
	     
	 //Read in the current sponsor element's information, after making sure it exists
	 var sponsorNode = xmlDocument.getElementsByTagName("sponsor")[i].firstChild;
		
   if(sponsorNode != null && sponsorNode != undefined){
		 
		var sponsorData = xmlDocument.getElementsByTagName("sponsor")[i].firstChild.nodeValue;
		
   }
    
   if(sponsorData != null && sponsorData != undefined){   
		
	  //Call the writeSponsors function to create the appropriate div
		writeSponsors(sponsorData,i);
		
   }
	
  }	
 
 }	

}


function writeSponsors(sponsorData,sponsorNum){

 /* The previous function already checked for any blank sponsor elements 
  * and shouldn't have called this function if they were blank
	  but just to make sure let's check again */
 
 if(sponsorData != ""){
  
  divSponsor = document.createElement("div");
	document.getElementById('begin').appendChild(divSponsor);
  sponsorId = divSponsor.id = "sponsor"+sponsorNum;
  document.getElementById(sponsorId).className = "sponsor";
	document.getElementById(sponsorId).innerHTML = "Sponsored by: <a href=\""+sponsorData+"\">"+sponsorData+"</a>";
	
 }

}